package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.mapper.AdChannelMapper;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.admin.service.AdChannelService;
import com.itheima.common.vo.PageResultVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class AdChannelServiceImpl extends ServiceImpl<AdChannelMapper, AdChannel> implements AdChannelService {

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @Override
    public PageResultVo<AdChannel> findpage(ChannelPageRequestDto dto) {
        IPage<AdChannel> pageSettings = new Page<>(dto.getPage(),dto.getSize());
        LambdaQueryWrapper<AdChannel> lqw = new LambdaQueryWrapper();
        lqw.like(StringUtils.isNotEmpty(dto.getName()),AdChannel::getName,dto.getName());
        lqw.eq(dto.getStatus()!=null,AdChannel::getStatus,dto.getStatus());
        page(pageSettings, lqw);
        return PageResultVo.pageResult(pageSettings.getCurrent(),
                pageSettings.getSize(),pageSettings.getTotal(),pageSettings.getRecords());
    }
}
